package com.smec.remes.module.submit.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.smec.moblie.BR;
import com.smec.moblie.R;
import com.smec.moblie.databinding.LayoutNullDataBinding;
import com.smec.moblie.databinding.LayoutRecyclerviewUnfinishBinding;
import com.smec.moblie.databinding.LayoutRecyclerviewWuliaoBinding;
import com.smec.remes.base.SmecBaseRecyclerViewHolder;
import com.smec.remes.bean.MatnrList;
import com.smec.remes.bean.SubmitFinish;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/12/20.
 */

public class SmecWuLiaoAdapter extends RecyclerView.Adapter<SmecBaseRecyclerViewHolder> {
    private static int  NULLDATA = 0;
    private static int  DATA = 1;
    private Context mcontext;
    private ArrayList<MatnrList> matnrListArrayList=new ArrayList<>();
    public void setArrayList( ArrayList<MatnrList> list){
        matnrListArrayList=list;
        notifyDataSetChanged();
    }

    public SmecWuLiaoAdapter(Context context) {
        this.mcontext=context;
    }

    @Override
    public SmecBaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(viewType == DATA){
            LayoutRecyclerviewWuliaoBinding layoutRecyclerviewWuliaoBinding=DataBindingUtil.inflate
                    (LayoutInflater.from(parent.getContext()), R.layout.layout_recyclerview_wuliao,parent,false);
            SmecBaseRecyclerViewHolder smecBaseRecyclerViewHolder=new
                    SmecBaseRecyclerViewHolder(layoutRecyclerviewWuliaoBinding.getRoot());
            smecBaseRecyclerViewHolder.setViewType(viewType);
            smecBaseRecyclerViewHolder.setBinding(layoutRecyclerviewWuliaoBinding);
            return smecBaseRecyclerViewHolder;
        }else {
            LayoutNullDataBinding layoutNullDataBinding = DataBindingUtil.inflate
                    (LayoutInflater.from(parent.getContext()), R.layout.layout_null_data,parent,false);
            SmecBaseRecyclerViewHolder smecBaseRecyclerViewHolder=new
                    SmecBaseRecyclerViewHolder(layoutNullDataBinding.getRoot());
            smecBaseRecyclerViewHolder.setViewType(viewType);
            smecBaseRecyclerViewHolder.setBinding(layoutNullDataBinding);
            return smecBaseRecyclerViewHolder;
        }
    }

    @Override
    public void onBindViewHolder(SmecBaseRecyclerViewHolder holder, int position) {
        if(holder.getViewType() == DATA) {
            LayoutRecyclerviewWuliaoBinding layoutRecyclerviewWuliaoBinding= (LayoutRecyclerviewWuliaoBinding) holder.getBinding();
            layoutRecyclerviewWuliaoBinding.setVariable(BR.wuliao,matnrListArrayList.get(position));
//            int num_one= Integer.parseInt(matnrListArrayList.get(position).getApplyQty())
//                    +Integer.valueOf(matnrListArrayList.get(position).getDistributeQty());
            layoutRecyclerviewWuliaoBinding.tvNumOne.setText(String.valueOf(matnrListArrayList.get(position).getUnSendQty())+" "+matnrListArrayList.get(position).getPkgUnit());

//            int num_two= Integer.valueOf(matnrListArrayList.get(position).getDistributeQty())
//                    -Integer.parseInt(matnrListArrayList.get(position).getReceiptQty());
//            Log.w("aa", matnrListArrayList.get(position).getDistributeQty());
//            Log.w("aa", matnrListArrayList.get(position).getReceiptQty());
//            Log.w("aa", String.valueOf(num_two));
            layoutRecyclerviewWuliaoBinding.tvNumTwo.setText(String.valueOf(matnrListArrayList.get(position).getUnConfrimQty())+" "+matnrListArrayList.get(position).getPkgUnit());
            layoutRecyclerviewWuliaoBinding.tvNumThree.setText(String.valueOf(matnrListArrayList.get(position).getConfrimedQty())+" "+matnrListArrayList.get(position).getPkgUnit());
            if(matnrListArrayList.get(position).getLineCodeStatus().equals("Enabled")){
                layoutRecyclerviewWuliaoBinding.tvLineCodeStatus.setVisibility(View.GONE);
                layoutRecyclerviewWuliaoBinding.number.setVisibility(View.VISIBLE);
            }else {
                layoutRecyclerviewWuliaoBinding.tvLineCodeStatus.setVisibility(View.VISIBLE);
                layoutRecyclerviewWuliaoBinding.number.setVisibility(View.GONE);
            }
        }
        holder.getBinding().executePendingBindings();//刷新界面
    }

    @Override
    public int getItemViewType(int position) {
        if(matnrListArrayList == null || matnrListArrayList.size() == 0){
            return NULLDATA;
        }else{
            return DATA;
        }
    }

    @Override
    public int getItemCount() {
        if(matnrListArrayList.size() == 0){
            return 1;
        }else{
            return matnrListArrayList.size();
        }
    }
}
